<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    *
    * Ajax Check Datablock Tag
    *
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @since 15.10.2005
    * @copyright essentialmind.com 2005
    *
    *********************************************************/

    /***
    * class ajaxAddDatablock
    ****
    * @package ajax
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    * @since 15.10.2005
    * @copyright essentialmind.com 2005
    ***/
    class ajaxCheckDatablockTag extends ajaxAction{

        public function process(){
            $nodeid = (int)$_REQUEST['node'];
            $pageid = (int)$_REQUEST['page'];
            $tag    = strip_tags($_REQUEST['tag']);
            $block  = (int)$_REQUEST['block'];
            
            //presume we are ok
            $this->r->status = false;
            
            //check tag
            if($pageid > 0){
                if($tit = $this->db->getOne("SELECT title FROM datablock_page_mapping AS dpm LEFT JOIN datablocks AS d ON dpm.blockid = d.id WHERE d.id != $block AND dpm.pageid = $pageid AND d.tag = '$tag'")){
                    $this->r->status = true;
                    $this->r->title  = $tit;
                }
            }else{
                if($tit = $this->db->getOne("SELECT title FROM datablock_node_mapping AS dpm LEFT JOIN datablocks AS d ON dpm.blockid = d.id WHERE d.id != $block AND dpm.nodeid = $nodeid AND d.tag = '$tag'")){
                    $this->r->status = true;
                    $this->r->title  = $tit;
                }
            }

        }
    }
?>